import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useRef } from "react";
import BlazeSlider from "blaze-slider";
import styles from "./index.module.less";
import { useMount, useSetState } from "ahooks";
import classNames from "classnames";
import { usePrevious, useUpdateEffect } from "ahooks";
import { registerNext, userInfo } from "../../api/user";
import { KEYCONST } from "../../enums";
import { useDispatch } from "react-redux";
import useServices from "../../hooks/useRequest";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var Invitecode = function() {
    var goindex = function goindex(e) {
        // console.log('gogogo')
        var data = {};
        if (e == "skip") {
            data = {
                nickname: state.name
            };
        } else {
            if (!state.invite) {
                return;
            }
            data = {
                nickname: state.name,
                invitationCode: state.invite
            };
        }
        services.registerNext(data, true).then(function(res) {
            console.debug("res", res);
            if (res.code == 200) {
                services.userInfo({}).then(function(res) {
                    localStorage.setItem(KEYCONST.userInfo, JSON.stringify(res.data));
                    dispatch.app.SET_USER_INFO(res.data);
                    dispatch.app.PUSH({
                        path: "/home"
                    });
                }).catch(function(err) {
                    console.log("err", err);
                });
            } else {
            // this.app._toast(res.msg)
            }
        }).catch(function(err) {
            console.log("err", err);
        });
    };
    var go1 = function go1() {
        // name ? index = 1 : null
        if (state.name) {
            setState({
                active: 1
            });
        }
    };
    var sliderWrap = useRef(null);
    var slider = useRef();
    var _useSetState = _sliced_to_array(useSetState({
        index: 0,
        name: "",
        invite: "",
        showthk: false,
        active: 0
    }), 2), state = _useSetState[0], setState = _useSetState[1];
    var prevAcitve = usePrevious(state.active);
    var dispatch = useDispatch();
    var services = useServices({
        registerNext: registerNext,
        userInfo: userInfo
    });
    useMount(function() {
        if (!slider.current) {
            slider.current = new BlazeSlider(sliderWrap.current, {
                all: {
                    autoplayDirection: "to right"
                }
            });
        }
        /** 组织拖拽 */ // slider.current.track!.onpointerdown = (e) => {
        //   e.stopPropagation();
        //   return false;
        // };
        slider.current.track.onpointerdown = null;
    });
    useUpdateEffect(function() {
        if ((prevAcitve || 0) > state.active) {
            var _slider_current;
            (_slider_current = slider.current) === null || _slider_current === void 0 ? void 0 : _slider_current.prev(state.active);
        } else {
            var _slider_current1;
            (_slider_current1 = slider.current) === null || _slider_current1 === void 0 ? void 0 : _slider_current1.next(state.active);
        }
    }, [
        state.active
    ]);
    return /*#__PURE__*/ _jsx("div", {
        className: styles.content,
        children: /*#__PURE__*/ _jsxs("div", {
            className: classNames("blaze-slider", styles["my-swipe"]),
            ref: sliderWrap,
            children: [
                /*#__PURE__*/ _jsx("div", {
                    className: "blaze-container",
                    children: /*#__PURE__*/ _jsx("div", {
                        className: "blaze-track-container",
                        children: /*#__PURE__*/ _jsxs("div", {
                            className: "blaze-track",
                            children: [
                                /*#__PURE__*/ _jsx("div", {
                                    children: /*#__PURE__*/ _jsxs("div", {
                                        className: styles.item1,
                                        children: [
                                            /*#__PURE__*/ _jsx("div", {
                                                className: classNames("Montserrat-Bold font-13 font-zi", styles.skip),
                                                onClick: function() {
                                                    return goindex("skip");
                                                },
                                                children: "SKIP"
                                            }),
                                            /*#__PURE__*/ _jsxs("div", {
                                                className: styles.box1,
                                                children: [
                                                    /*#__PURE__*/ _jsx("img", {
                                                        className: styles.box1bg,
                                                        src: require("../../assets/public/yqcodek.svg"),
                                                        alt: ""
                                                    }),
                                                    /*#__PURE__*/ _jsxs("div", {
                                                        className: styles.box1int,
                                                        children: [
                                                            /*#__PURE__*/ _jsx("div", {
                                                                className: "Montserrat-ExtraBold font-12 font-zi text-center",
                                                                children: "CHOOSE A NICKNAME"
                                                            }),
                                                            /*#__PURE__*/ _jsx("div", {
                                                                className: classNames("flex-center", styles.intk, "flex-j-around"),
                                                                style: {
                                                                    marginTop: "4px",
                                                                    marginLeft: "32px"
                                                                },
                                                                children: /*#__PURE__*/ _jsxs("div", {
                                                                    className: classNames(styles.intp, "flex-center"),
                                                                    children: [
                                                                        /*#__PURE__*/ _jsx("input", {
                                                                            maxLength: 15,
                                                                            className: classNames(styles.intzi, "Montserrat-SemiBold"),
                                                                            "placeholder-class": styles.inttszi,
                                                                            type: "text",
                                                                            "v-model": "name",
                                                                            value: state.name,
                                                                            onChange: function(e) {
                                                                                setState({
                                                                                    name: e.target.value
                                                                                });
                                                                            },
                                                                            placeholder: ""
                                                                        }),
                                                                        /*#__PURE__*/ _jsx("div", {
                                                                            className: classNames(styles.btn, "Montserrat-ExtraBold font-white", state.name ? "" : styles.btnh),
                                                                            onClick: go1,
                                                                            children: "GO"
                                                                        })
                                                                    ]
                                                                })
                                                            }),
                                                            /*#__PURE__*/ _jsx("div", {
                                                                className: "Montserrat-Medium font-zi text-center font-10",
                                                                style: {
                                                                    marginTop: "3px"
                                                                },
                                                                children: "Maximum of 15 characters"
                                                            })
                                                        ]
                                                    })
                                                ]
                                            })
                                        ]
                                    })
                                }),
                                /*#__PURE__*/ _jsx("div", {
                                    children: /*#__PURE__*/ _jsxs("div", {
                                        className: styles.item1,
                                        children: [
                                            /*#__PURE__*/ _jsxs("div", {
                                                className: styles.wel,
                                                children: [
                                                    /*#__PURE__*/ _jsx("div", {
                                                        className: "Montserrat-Medium font-30 font-zi text-center",
                                                        children: "Welcome!"
                                                    }),
                                                    /*#__PURE__*/ _jsx("div", {
                                                        className: "Montserrat-Regular font-18 font-zi text-center mt-5",
                                                        children: state.name
                                                    })
                                                ]
                                            }),
                                            /*#__PURE__*/ _jsx("div", {
                                                className: classNames("Montserrat-Bold font-13 font-zi", styles.skip),
                                                onClick: function() {
                                                    return goindex("skip");
                                                },
                                                children: "SKIP"
                                            }),
                                            /*#__PURE__*/ _jsxs("div", {
                                                className: styles.box2,
                                                children: [
                                                    /*#__PURE__*/ _jsx("div", {
                                                        className: styles.king,
                                                        children: /*#__PURE__*/ _jsx("img", {
                                                            className: styles.king,
                                                            src: require("../../assets/public/king.png")
                                                        })
                                                    }),
                                                    /*#__PURE__*/ _jsx("div", {
                                                        className: classNames("flex-center", styles.intk2, "flex-j-around"),
                                                        style: {
                                                            marginTop: "0px",
                                                            marginLeft: "7px"
                                                        },
                                                        children: /*#__PURE__*/ _jsxs("div", {
                                                            className: classNames(styles.intp, "flex-center"),
                                                            style: {
                                                                width: "251px"
                                                            },
                                                            children: [
                                                                /*#__PURE__*/ _jsx("input", {
                                                                    className: classNames(styles.intzi, "Montserrat-SemiBold"),
                                                                    "placeholder-class": styles.inttszi,
                                                                    type: "text",
                                                                    "v-model": "invite",
                                                                    value: state.invite,
                                                                    onChange: function(e) {
                                                                        setState({
                                                                            invite: e.target.value
                                                                        });
                                                                    },
                                                                    placeholder: ""
                                                                }),
                                                                /*#__PURE__*/ _jsx("div", {
                                                                    className: classNames(styles.btn, "Montserrat-ExtraBold font-white", state.invite ? "" : styles.btnh),
                                                                    onClick: function() {
                                                                        return goindex("go");
                                                                    },
                                                                    children: "GO"
                                                                })
                                                            ]
                                                        })
                                                    }),
                                                    /*#__PURE__*/ _jsxs("div", {
                                                        className: classNames("text-center mt-5", styles.box2zi),
                                                        children: [
                                                            /*#__PURE__*/ _jsx("text", {
                                                                className: "Montserrat-ExtraBold font-12 font-zi",
                                                                children: "ENTER A REFERRAL CODE"
                                                            }),
                                                            /*#__PURE__*/ _jsx("text", {
                                                                className: "Montserrat-Medium font-12 font-zi ml-5",
                                                                onClick: function() {
                                                                    setState({
                                                                        showthk: !state.showthk
                                                                    });
                                                                },
                                                                children: "(OPTIONAL)"
                                                            }),
                                                            /*#__PURE__*/ _jsx("img", {
                                                                className: classNames(styles.icon28, "ml-5", styles.box2qes),
                                                                src: require("../../assets/public/ques.png"),
                                                                onClick: function() {
                                                                    setState({
                                                                        showthk: !state.showthk
                                                                    });
                                                                }
                                                            }),
                                                            state.showthk && /*#__PURE__*/ _jsx("div", {
                                                                className: styles.mc,
                                                                "v-if": "showthk",
                                                                onClick: function() {
                                                                    setState({
                                                                        showthk: !state.showthk
                                                                    });
                                                                }
                                                            }),
                                                            /*#__PURE__*/ _jsx("div", {
                                                                className: styles.thkd,
                                                                children: state.showthk && /*#__PURE__*/ _jsxs("div", {
                                                                    className: styles.thk,
                                                                    "v-if": "showthk",
                                                                    children: [
                                                                        /*#__PURE__*/ _jsx("img", {
                                                                            className: styles.thkbg,
                                                                            src: require("../../assets/public/thk.png")
                                                                        }),
                                                                        /*#__PURE__*/ _jsx("div", {
                                                                            className: classNames(styles.thkwa, "Montserrat-Regular font-10"),
                                                                            children: "Key in your referral code to give credit to whoever invited you over to the NFKingdom! If you don’t have one, no problem! Referring your friends and family to join the NFKingdom gives you priority access and privileges!"
                                                                        })
                                                                    ]
                                                                })
                                                            })
                                                        ]
                                                    })
                                                ]
                                            })
                                        ]
                                    })
                                })
                            ]
                        })
                    })
                }),
                /*#__PURE__*/ _jsxs("div", {
                    className: styles.indicatorclass,
                    children: [
                        /*#__PURE__*/ _jsx("div", {
                            className: classNames(state.active == 0 ? styles.dian : styles.dian2, styles.dian1)
                        }),
                        /*#__PURE__*/ _jsx("div", {
                            className: classNames(state.active == 1 ? styles.dian : styles.dian2)
                        })
                    ]
                })
            ]
        })
    });
};
export default Invitecode;

 //# sourceMappingURL=index.js.map